<?php

class Antz_Form_Components_TimeDateSelect extends Antz_Form_Component
{
    protected $options = array();
    protected $type = 'TimeDateSelect';

    public function __construct($name, $label, $value='', $tstamp=''){
        $this->id = 'sel'.rand();
        if($tstamp == '') $tstamp = time();
        $this->name = $name;
        $this->label = $label;
        if($value=='') $value = array('month'=>date('n', $tstamp), 'year'=>date('Y', $tstamp), 'day'=>date('j', $tstamp), 'hour'=>date('H', $tstamp), 'minute'=>date('i', $tstamp));

        $this->value = $value;
        $this->setLang('en');
        $timeVals = array(
            'hour'=>$value['hour'],
            'minute'=>$value['minute']
        );
        $dateVals = array(
            'month'=>$value['month'],
            'year'=>$value['year'],
            'day'=>$value['day']
        );
        $this->timeSel = Antz::newObject('Antz_Form_Components_TimeSelect', array($name, $label, $timeVals));
        $this->dateSel = Antz::newObject('Antz_Form_Components_DateSelect', array($name, $label, $dateVals));
    }

    public function setLang($lang='en'){
        $lang = 'en';
        switch($lang){
            case 'en':

            break;
        }
    }

    public function fetchUnixTime($key){
        $mth = (int) post($key.'Month');
        $y = (int) post($key.'Year');
        $d = (int) post($key.'Day');
        $h = (int) post($key.'Hour');
        $min = (int) post($key.'Minute');
        $tstamp = mktime($h, $min, 0, $mth, $d, $y);
        return $tstamp;
    }

    public function render($wrap=true, $label=true){
        // generate the month options
        global $gCms;
     	$Antz = Antz::registry('Antz');
     	if($this->required) $this->aftertext = '<span class="required"><img src="'.$gCms->config['root_url'].'/modules/Antz/images/required.gif" alt="'.$Antz->Lang('required').'" /></span>'.$this->aftertext;

        $this->timeSel->showLabel(false);
        $this->timeSel->setWrap(false);
        $this->dateSel->showLabel(false);
        $this->dateSel->setWrap(false);
        $returnString = $this->timeSel->render().$this->dateSel->render().'<div class="aftertext">'.$this->aftertext.'</div>';
        if($label) $returnString = '<label>'.$this->label.'</label>'.$returnString;
        if($wrap) return $this->wrap($returnString);
        else return $returnString;
    }
}
